package edu.dgut.bbssystem.service.impl;

import edu.dgut.bbssystem.common.Constant;
import edu.dgut.bbssystem.common.PageInfo;
import edu.dgut.bbssystem.mapper.MessageMapper;
import edu.dgut.bbssystem.pojo.Message;
import edu.dgut.bbssystem.pojo.User;
import edu.dgut.bbssystem.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class MessageServiceImpl implements MessageService {
    @Autowired
    private MessageMapper messageMapper;
    @Override
    public int add(Message message) {
        int result = Constant.FAIL;
        int insert  = messageMapper.insert(message);
        if (insert > 0){
            result = Constant.SUCCESS;
        }
        return result;
    }

    @Override
    public int deleteMessage(int id) {
        int result = messageMapper.deleteByPrimaryKey(id);
        if(result > 0){
            return Constant.SUCCESS;
        }else{
            return Constant.FAIL;
        }
    }

    @Override
    public int newMessageCount(int userId) {
        int count = messageMapper.getNewMessageCount(userId);
        return count;
    }

    @Override
    public PageInfo<User> pageQueryAllByReceiver(int pageNum, int pageSize, int userId) {
        return null;
    }

    @Override
    public int getMessageVo(int userId) {

        return 0;
    }
}
